export default class bg extends Laya.Script {
    speed=20;
    height=null;
    width=null;
    iszuo=false;
    isyou=false;
    isqianjing=true;

    owner=this.owner as Laya.Sprite
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    constructor() { super(); }
    
    onAwake(){
        Laya.stage.on("gamer2",this,function(){this.owner.texture="res/StarlitSky1.png";Laya.stage.event("jinyong1")});
        Laya.stage.on("homepege",this,function(){this.owner.texture="res/StarlitSky.png"})
        Laya.stage.on("zuo",this,function(){this.iszuo=true;this.isyou=false;this.isqianjing=false})
        Laya.stage.on("you",this,function(){this.isyou=true;this.iszuo=false;this.isqianjing=false})
        Laya.stage.on("qianjing",this,function(){this.isyou=false;this.iszuo=false;this.isqianjing=true})
        this.height=this.owner.height;
        this.width=this.owner.width;
        Laya.timer.frameLoop(1,this,this.frameLoop)
        }
        frameLoop(){
        if(this.iszuo){
                this.owner.x+=this.speed;
            if(this.owner.x>=this.width){
            this.owner.x-=this.width*2;
            }}
        if(this.isyou){
            this.owner.x-=this.speed;
            if(this.owner.x<=-this.width){
            this.owner.x+=this.width*2;
            }
        }
        if(this.isqianjing){
            this.owner.y+=this.speed;
            if(this.owner.y>=this.height){
            this.owner.y-=this.height*2;}}
    }
    
}